package com.meizi.codegenerate.tool.page;

import io.swagger.annotations.ApiModel;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author GG Bond
 * @date 2023/3/14 - 16:47 - 星期二
 * @project lambda
 * @package com.meizi.codegenerate.factory
 * @description 分页参数
 */
@Data
@ApiModel(description = "分页数据")
public class PageParam implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 从1开始
     */
    @NotNull(message = "{page.null}")
    private Integer page = 1;

    /**
     * 数量
     */
    @NotNull(message = "{limit.null}")
    private Integer pageSize = 10;

    /**
     * 排序字段
     */
    private String orderField = "";

    /**
     * String ASC = "asc"; String DESC = "desc";
     */
    private String order = "";

    public Map toMap() {
        try {
            Map<String, Object> params = new HashMap<>();
            params.put("page", this.page + "");
            params.put("pageSize", this.pageSize + "");
            params.put("orderField", this.orderField);
            params.put("order", this.order);
            return params;
        } catch (Exception var2) {
            return null;
        }
    }
}
